﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Transactions;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using DotNetOpenAuth.AspNet;
using Microsoft.Web.WebPages.OAuth;
using WebMatrix.WebData;
using mscook.mvc.Filters;
using mscook.mvc.Models;
using mscook.core.services;
using mscook.mvc.Core;
using mscook.core.domain;
using System.Security.Principal;
using mscook.mvc.core;
namespace mscook.mvc.Controllers
{
    public class HotelController : BaseController
    {
        //
        // GET: /Hotel/
        private ILoginUserService iLoginUserService;
        private IHotelService iHotelService;
        public HotelController(IHotelService iHotelService, IActionBonusSettingService actionBonusSettingService, IResourceBonusSettingService resourceBonusSettingService, ILoginUserService loginUserService)
            : base(actionBonusSettingService, resourceBonusSettingService, loginUserService)
        {
            this.iLoginUserService = loginUserService;;
            this.iHotelService = iHotelService;
        }
        public ActionResult Index(string[] resourceTypes, string num = "")
        {
            HotelModel hotelModel = new HotelModel();
            long total = 0;
            PageBreakHelper pageBreakHelper = new PageBreakHelper();
            pageBreakHelper.Init(num, "12");
            if (resourceTypes != null)
            {
                IList<string> resoureTypeList = resourceTypes.Where(o => !string.IsNullOrEmpty(o)).ToList();
                //cookBookModel.CookBookList = iCookBookService.SelectPageList(pageBreakHelper.Start, pageBreakHelper.PerValue, out total);
                if (resoureTypeList.Count == 0)
                {
                    hotelModel.HotelList = iHotelService.SelectPageList(pageBreakHelper.Start, pageBreakHelper.PerValue, out total);
                }
                else
                {
                    hotelModel.HotelList = iHotelService.SelectLimitbyIds(GetRsourceIdsByTypes(resoureTypeList, PurchasedCategory.Hotel), pageBreakHelper.Start, pageBreakHelper.PerValue, out total);
                    hotelModel.SelectResourceTypes = resoureTypeList;
                }
            }
            else
            {
                hotelModel.HotelList = iHotelService.SelectPageList(pageBreakHelper.Start, pageBreakHelper.PerValue, out total);
            }
            pageBreakHelper.SetViewDataKeys(ViewData, ViewBag, total);
            InitSourceType(hotelModel, PurchasedCategory.Hotel);

            InitNavBar();
            return View(hotelModel);
        }

        public ActionResult ReadHotel(string id)
        {
         
            Hotel hotel = iHotelService.Get(id);
            if (hotel != null)
            {
                ReadHotelModel readHotelModel = new ReadHotelModel() {Hotel=hotel };
                readHotelModel.LoginUser = CurrentUser;
                readHotelModel.Magazine = GetPushMagazine();
                InitNavBar();
                return View(readHotelModel);
            }
            return RedirectToAction("index");
        }

    }
}
